package com.ruoyi.common.utils;

import org.dozer.DozerBeanMapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Bean 的 类型转化
 * @Title:
 * @Description:
 * @Company:
 * @Author:zp
 * @Created Date:2021年6月17日
 */
public class BeanMapperUtil {

	private static DozerBeanMapper dozer = new DozerBeanMapper();

	public static <T> T map(Object sourceObject, Class<T> destObjectclazz) {
		return (sourceObject == null) ? null : dozer.map(sourceObject, destObjectclazz);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static <T, S> List<T> mapList(Collection<S> sourceList, Class<T> destObjectclazz) {

		if (sourceList == null) {
			return null;
		}

		List destinationList = new ArrayList();

		for (Iterator it = sourceList.iterator(); it.hasNext();) {
			destinationList.add(map(it.next(), destObjectclazz));
		}
		return destinationList;
	}
}
